package com.zuoye.day13;



import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProTest {
    public static void main(String[] args) {
        List<Product4> list = new ArrayList<>();
        Product4 p1 = new Product4("宝洁", "洗手粉", 18.5);
        Product4 p2 = new Product4("联合利华", "肥皂", 4.5);
        Product4 p3 = new Product4("宝洁", "牙膏", 32.5);
        Product4 p4 = new Product4("宝洁", "毛巾", 14.5);
        Product4 p5 = new Product4("洁利", "洗面奶", 26.0);
        Product4 p6 = new Product4("好迪", "洗发水", 27.5);
        Product4 p7 = new Product4("多芬", "沐浴露", 38.5);
        Product4 p8 = new Product4("宝洁", "洗洁精", 3.4);
        list.add(p1);
        list.add(p2);
        list.add(p3);
        list.add(p4);
        list.add(p5);
        list.add(p6);
        list.add(p7);
        list.add(p8);
        System.out.println(list);

        System.out.println("=======================");
        Map<String,List<Product4>> proMap = new HashMap<>();
        for (Product4 product4 : list){
            String brand = product4.getBrand();
            if (proMap.containsKey(brand)){
                List<Product4> product = proMap.get(brand);
                product.add(product4);

            }else {
                List<Product4> product = new ArrayList<>();
                product.add(product4);
                proMap.put(brand,product);

            }
            System.out.println(proMap);

        }
       /* BigDecimal totalMoney = list.stream().map(Product4::getCost).reduce(BigDecimal.ZERO,BigDecimal::add);
        System.out.println(totalMoney);*/




    }


}
